package com.fishleap.sqlSession;

import com.fishleap.config.XmlConfigBuilder;
import com.fishleap.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @author zlg
 * @create 2020-04-21 22:41
 */
public class SqlSessionFactoryBuilder {

    /*
     * 1.使用dom4j解析传入的配置文件输入流,封装到定义的两个容器中
     * 2.创建sqlSessionFactory对象
     */
    public SqlSessionFactory build(InputStream inputStream) throws DocumentException, PropertyVetoException {
        // 1.使用dom4j解析配置文件,将解析的内容(数据源,sql列表)封装到Configuration中
        // 创建XmlConfiguration对象时同时初始化Configuration对象属性
        XmlConfigBuilder xmlConfigBuilder = new XmlConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfiguration(inputStream);

        // 2.创建sqlSessionFactory对象
        SqlSessionFactory sqlSessionFactory = new DefaultSqlSessionFactory(configuration);

        return sqlSessionFactory;
    }

}
